#pragma once

#include <vector>

using std::vector;
//using namespace std;

namespace shr
{
	template<size_t N>
	class bit_map
	{
	private:
		typedef bit_map<N> self;

	public:
		bit_map()
		{
			_bitMap.resize(N / 32 + 1);
		}

		self& set(size_t n)
		{
			int i = n / 32;
			int j = n % 32;
			_bitMap[i] |= (1 << j);
			return *this;
		}

		self& reset(size_t n)
		{
			int i = n / 32;
			int j = n % 32;
			_bitMap[i] &= (~(1 << j));
			return *this;
		}

		self& flip(size_t n)
		{
			if (test(n)) {
				reset(n);
			}
			else {
				set(n);
			}
			return *this;
		}

		bool test(size_t n)
		{
			int i = n / 32;
			int j = n % 32;
			return (_bitMap[i] & (1 << j));
		}

	private:
		vector<int> _bitMap;
	};
}